package com.example.blog.controller;

import com.example.blog.dto.AddMemberReqDto;
import com.example.blog.dto.QueryMemberResDto;
import com.example.blog.dto.UpdateMemberReqDto;
import com.example.blog.dto.base.IdRequestDto;
import com.example.blog.response.ResponseModelDto;
import com.example.blog.response.ResponseModels;
import com.example.blog.service.CommunMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Admin
 */
@RestController
@Api(value = "聊天用户接口", tags = "聊天用户接口")
@RequestMapping("/member")
public class CommunMemberController {

    @Resource
    private CommunMemberService communMemberService;

    @PostMapping("/addMember")
    @ApiOperation("添加聊天用户接口")
    public ResponseModelDto addMember(@RequestBody @Validated AddMemberReqDto reqDto){
        if(communMemberService.addMember(reqDto)){
            return ResponseModels.ok();
        }else{
            return ResponseModels.commonException("添加失败");
        }
    }

    @PostMapping("/updateMember")
    @ApiOperation("修改聊天用户接口")
    public ResponseModelDto updateMember(@RequestBody @Validated UpdateMemberReqDto reqDto){
        if(communMemberService.updateMember(reqDto)){
            return ResponseModels.ok();
        }else{
            return ResponseModels.commonException("修改失败");
        }
    }

    @GetMapping("/getMember")
    @ApiOperation("查询在线聊天用户接口")
    public ResponseModelDto<List<QueryMemberResDto>> getMember(@Validated IdRequestDto reqDto){
        return ResponseModels.ok(communMemberService.getMember(reqDto));
    }

}
